package com.ruoyi.mq;

import com.alibaba.fastjson.JSON;
import com.ruoyi.domain.Tenement;
import com.ruoyi.domain.Tenementsask;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
@RocketMQMessageListener(
        consumerGroup="alarm-Consummer",
        topic="alarm-topic",
        selectorExpression="alarm-tag"
)
@Slf4j
public class AlarmConsummer implements RocketMQListener<MessageExt> {
    @Override
    public void onMessage(MessageExt messageExt) {
        byte[] body = messageExt.getBody();
        List<Tenementsask> tenementsasks = JSON.parseArray(JSON.toJSONString(body), Tenementsask.class);
        Date date = new Date();
        tenementsasks.forEach(t->{
            Date endTime = t.getEndTime();
            Integer status = t.getStatus();
            if (endTime.before(date) && status==0){
                log.info("核酸检查报警：任务名："+t.getTaskName()+"姓名："+t.getName()+"检查结果：未检测" );
                log.info("亲爱的住户:"+t.getName()+"您好，你在"+t.getStartTime()+"时的核酸未完成，请尽快完成");
            }
        });
    }
}
